<?php

/**
 * Well Framework
 * 
 * Contains Front Controller pattern class
 * 
 * @package     Well
 *
 * @author Valerii Lazarevych <valeriy.fremar@gmail.com>
 */

/**
 * Abstract Class Command
 */
abstract class Command
{
    /**
     * Command own view
     * 
     * @var type View obj
     */
    protected $view;
    
    /**
     * Contain app inbox request
     * @var Request $request 
     */
    protected $request;
    
    /**
     * Contain user session data
     * @var Session $sesion 
     */
    protected $session;
    
    /**
     * Inheritans classes suffix
     * 
     * @var string  |   'Command'
     */
    protected $classNameSuffix  =   'Command';
        

    /**
     * Initialize command view obj
     * 
     * @final
     */
    final function __construct()
    {   
        // Instanceat helper view
        $this->view   =   new View( strtolower(strstr(get_class($this), $this->classNameSuffix, true))  );                      
        
        // Get user session data
        $this->session  =   ApplicationRegistry::get('session');
    }
    
    /**
     * This-> doExecute() decoration
     * 
     * @param Request $oRequest 
     */
    public function execute(Request $oRequest)
    {
        // Init request for executing command        
        $this->request  =   $oRequest;
        
        // Executing command
        $this->doExecute();
        
        // Assign executed command view to app layout
        ApplicationRegistry::get('layout')-> setCommandView( $this->view );
    }
    
    /**
     * The future implementation of commands
     * 
     * @abstract
     */
    abstract protected function doExecute();
                
}

